package org.elsfs.cloud.common.mybatis.ext.sql.support.condition;


import org.apache.commons.codec.binary.CharSequenceUtils;
import org.elsfs.cloud.common.mybatis.ext.sql.SqlFragment;
import org.elsfs.cloud.common.util.lang.StringUtils;

/**
 * 条件项
 *
 */
public interface ConditionItem extends SqlFragment {

    /**
     * 剔除条件SQL头部多余的关键词
     *
     * @param conditionSql 条件SQL
     * @return 合理的条件SQL
     */
    static String stripHeaderKeyword(String conditionSql) {
        if (conditionSql.startsWith("AND ")) {
            return StringUtils.strip(conditionSql, "AND ");
        }

        if (conditionSql.startsWith("OR ")) {
            return StringUtils.strip(conditionSql, "OR ");
        }

        return conditionSql;
    }
}
